package cn.zf.spring5.testdemo;

import cn.zf.spring5.autowire.Emp;
import cn.zf.spring5.bean.Orders;
import cn.zf.spring5.collectiontype.Book;
import cn.zf.spring5.collectiontype.Cource;
import cn.zf.spring5.collectiontype.Stu;
import cn.zf.spring5.factorybean.MyBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class TestList {
    @Test
    public void testCollection(){
        //1 读取配置文件
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");

        Stu stu = context.getBean("stu", Stu.class);
        stu.testPrint();
    }

    @Test
    public void testBook(){
        //1 读取配置文件
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean2.xml");

        Book book1 = context.getBean("book", Book.class);
        Book book2 = context.getBean("book", Book.class);

        //book.testPrint();

        System.out.println(book1);
        System.out.println(book2);
    }


    @Test
    public void testBean(){
       ApplicationContext context =
               new ClassPathXmlApplicationContext("bean3.xml");

        Cource myBean = context.getBean("myBean", Cource.class);

        System.out.println(myBean);
    }
    @Test
    public void testBean2(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean4.xml");

        Orders orders = context.getBean("orders", Orders.class);
        System.out.println("第四步：获取创建的bean实例");
        System.out.println(orders);

        //手动销毁bean实例
        ((ClassPathXmlApplicationContext)context).close();

    }
    @Test
    public void testAutoWire(){
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean5.xml");
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);

    }
}
